package com.ofek.eventos.gui.list_table;


import java.awt.BorderLayout;
import java.awt.Color;
import java.util.ArrayList;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.SwingConstants;

/**
 * The TableFrame is a SONAFrame that contains all methods to set table model into the frame
 *  
 * @author Ofek Ron
 * @author Avihay Avitan
 * @author Nitzan Inbar
 * @author Sasha Rozenblum
 */
public class ListTableFrame<T> extends JFrame {
	/**
	 * mTable - JTable of this frame
	 */
	protected ListTable<T> listTable;

	/**
	 * 
	 * @param title
	 * @param table
	 * @param listener
	 */
	public ListTableFrame(final String title,final ArrayList<T> table,final ListTableClickListener<T> listener) {
		this(title,table);
		addListTableClickListener(listener);

	}
	/**
	 * Constructs the TableFrame with title and table
	 * @param title - the title of this frame
	 * @param table - the table to view in this frame
	 */
	public ListTableFrame(final String title,final ArrayList<T> table) {
		this(title);
		setTable(listTable=new ListTable<T>(new ListTableModel<T>(table)));
	}

	public ListTableFrame(final String title) {
		setTitle(title);
	}
	/**
	 * Set the table params to display to user
	 * @param table - the table to set 
	 */
	public void setTable( final ListTable<T> table) {
		listTable = table;
		listTable.setRowHeight(30);
		//		listTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
		listTable.setGridColor(Color.LIGHT_GRAY);
		listTable.setShowGrid(true);
		listTable.setShowVerticalLines(false);
		listTable.setShowHorizontalLines(true);
		new TableColumnAdjuster(listTable).adjustColumns();
		if (listTable.getModel().getRowCount()<=0) {
			onEmpty();
			return;
		}
		internalSetTable(listTable);
	}


	protected void onEmpty() {
		getContentPane().add(new JLabel("No Data to Display",SwingConstants.CENTER));
	}
	protected void internalSetTable(final ListTable<T> listTable2) {
		getContentPane().add(new JScrollPane(listTable2));
	}
	public void addListTableClickListener(final ListTableClickListener<T> listener) {
		listTable.addListTableClickListener(listener);
	}
}
